//子游戏加载进度
class gameLoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }

    private waitText: eui.Label;
    private waitImgBg: egret.Bitmap;
    private waitImg: egret.Bitmap;
    private bg: egret.Sprite = new egret.Sprite();
    private w: number = 0;
    private h: number = 0;
    private textField: egret.TextField;

    private createView(): void {
        this.w = egret.MainContext.instance.stage.stageWidth;
        this.h = egret.MainContext.instance.stage.stageHeight;

        this.bg.graphics.beginFill(0x000000, 0.2);
        this.bg.graphics.drawRect(0, 0, this.w, this.h);
        this.bg.graphics.endFill();
        this.bg.width = this.w;
        this.bg.height = this.h;
        this.addChild(this.bg);
        this.touchEnabled = true;

        this.waitImgBg = new egret.Bitmap;
        this.waitImgBg.texture = RES.getRes("loadingBg");
        this.waitImgBg.x = this.w / 2;
        this.waitImgBg.y = this.h / 2;
        this.waitImgBg.anchorOffsetX = this.waitImgBg.width / 2;
        this.waitImgBg.anchorOffsetY = this.waitImgBg.height / 2;
        this.addChild(this.waitImgBg);

        this.waitImg = new egret.Bitmap;
        this.waitImg.texture = RES.getRes("loadingArrow");
        this.waitImg.x = this.w / 2;
        this.waitImg.y = this.h / 2;
        this.waitImg.anchorOffsetX = this.waitImg.width / 2;
        this.waitImg.anchorOffsetY = this.waitImg.height / 2;
        this.addChild(this.waitImg);

        this.textField = new egret.TextField();
        this.textField.size = 24;
        this.textField.textColor = 0xFFFFFF;
        this.textField.bold = true;
        this.textField.stroke = 1;
        this.textField.strokeColor = 0xE06A16;
        this.addChild(this.textField);
        this.textField.width = 100;
        this.textField.x = this.w / 2 - this.textField.width / 2;
        this.textField.y = this.waitImg.y + 50;
        this.textField.textAlign = "center";
        this.textField.text = "0%";

        EffectUtils.rotationEffect(this.waitImg, 1000);
    }

    public onProgress(current: number, total: number): void {
        this.textField.text = Math.round((current / total) * 100) + "%";
    }
}
